#!/bin/ash -efu

PROG='TEST'

create_temporary_test1() { # UnitTest
	local out result rc=0
	out="$(./temp-data/001-temp)" || rc=$?

	assertEquals "rc=$rc" "$rc" "0"

	result="$(printf '%s\n' "$out" |
		while read -r d; do
			[ ! -e "$d" ] ||
				printf '"%s" exists;\n' "$d"
		done
	)" ||:
	assertEquals "$result" "$result" ""
}

create_temporary_test2() { # UnitTest
	local out result n rc=0
	out="$(./temp-data/002-temp)" || rc=$?

	assertEquals "rc=$rc" "$rc" "42"

	n=0
	result="$(printf '%s\n' "$out" |
		while read -r d; do
			[ "$n:$d" != "1:DONE 42" ] ||
				continue
			[ ! -e "$d" ] ||
				printf '"%s" exists;\n' "$d"
			n=$(($n+1))
		done
	)" ||:
	assertEquals "$result" "$result" ""
}

create_temporary_test3() { # UnitTest
	local out result n rc=0
	out="$(./temp-data/003-temp)" || rc=$?

	assertEquals "rc=$rc" "$rc" "42"

	n=0
	result="$(printf '%s\n' "$out" |
		while read -r d; do
			[ "$n:$d" != "2:DONE 42" ] ||
				continue
			[ ! -e "$d" ] ||
				printf '"%s" exists;\n' "$d"
			n=$(($n+1))
		done
	)" ||:
	assertEquals "$result" "$result" ""
}
